#include "command.h"

/* Usage: ./client 127.0.0.1 12345*/
int main(int argc, char *argv[]){
    /* ARGS_CHECK(argc, 3); */
    argv[1] = "127.0.0.1";                                                                       
    argv[2] = "12345";
    int sockfd = socket(AF_INET, SOCK_STREAM, 0);

    struct sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(atoi(argv[2]));
    addr.sin_addr.s_addr = inet_addr(argv[1]);

    int ret = connect(sockfd, (struct sockaddr *)&addr, sizeof(addr));
    ERROR_CHECK(ret, -1, "connect");

    // 客户端刚启动时打印一次客户端本地的当前目录有哪些文件
    print_files_in_dir();
    while(1){
        // 注释部分可能发生两次函数调用, 作为警醒, 保留!
        //if(-1 == validate_and_parse_command(sockfd) || -2 == validate_and_parse_command(sockfd)){
        //    continue;
        //}
        int ret = validate_and_parse_command(sockfd);
        if(-1 == ret || -2 == ret){
            continue;
        }
    }

    close(sockfd);
    return 0;
}

